home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1996 March
/
EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso
/
earcd
/
util2
/
gdmgt205.lha
/
GadMget
/
AutoFTP.rexx
next >
Wrap
OS/2 REXX Batch file
|
1995-08-05
|
10KB
|
311 lines
/*****************************************************************************/
/* */
/* AutoFTP.rexx : an ARexx script to automatically a list of files from an */
/* Aminet archive site. When run, the new RECENT listing of */
/* the site is downloaded, and GadMGet is run on that */
/* listing. After GadMGet is terminated, GadMGet's output is */
/* sent to ncFTP, which automatically connects to the site */
/* and downloads the programs specified by the user. */
/* */
/* Don't use AutoFTP unless you have AmiTCP, GadMGet, and ncFTP already */
/* working correctly. AutoFTP relies on these programs to work. */
/* */
/* */
/* Command line Switches accepted : */
/* YES -- Automatically download a new RECENT file */
/* NO -- Don't download a RECENT file */
/* DEBUG -- Write all AmigaDOS commands executed to stdout */
/* */
/* If neither of the above is specified, a requester will be displayed */
/* asking the user whether or not to get a new RECENT file or not. */
/* */
/*****************************************************************************/
/**************************************************************************/
/* ---------- ADJUST THESE PARAMETERS TO FIT YOUR PREFERENCES ----------- */
/**************************************************************************/
/* The Aminet FTP Site you prefer to use */
AminetSite = "ftp.netnet.net"
/* The root directory of Aminet within that site */
AminetRootDir = "/pub/aminet"
/* The directory you want your copy of RECENT to be in */
LocalRecentDir = "dh0:"
/* Path & Filename of GadMGet executable */
GadMGet = "GadMget"
/* Path & Filename of ncFTP executable */
ncFTP = "amitcp:bin/ncFTP"
/* Any miscellaneous startup arguments you wish to be included
on GadMGet's command line call. See GadMGet documentation on
"Startup Options" for a list of possible options. */
GadMGetArgs = ""
/* The directory path you want AutoFTP to download files to. */
DownloadDir = "dh0:"
/* Do you want AutoFTP to keep saved selected lines from previous
GadMget sessions? */
PreserveSelected = YES
/* Do you want AutoFTP to remove lines from the new RECENT file that you
already have selected in the old RECENT file? (This option is only
significant if PreserveSelected is YES) */
DoPruning = YES
/**************************************************************************/
/* ------- END USER PARAMETERS --- DO NOT MODIFY BELOW THIS LINE -------- */
/**************************************************************************/
/**************************************************************************/
/* ---------------------- BEGIN AUTOFTP SCRIPT CODE --------------------- */
/**************************************************************************/
options results
parse arg CommandLineArg
DownloadRECENT = MAYBE
Debug = FALSE
CommandLineArg = upper(CommandLineArg)
if (CommandLineArg == "?") then do
say "AutoFTP: AutoFTP YES/S NO/S DEBUG/S"
exit
end
if (CommandLineArg == "YES") then DownloadRECENT = YES
if (CommandLineArg == "NO") then DownloadRECENT = NO
if (CommandLineArg == "DEBUG") then do
say "AutoFTP: Debug mode on."
Debug = TRUE
end
if (DownloadRECENT == MAYBE) then do
/* Load rexxreqtools.library if possible */
if (show('L','rexxreqtools.library')) then RexxReqToolsLoaded = 1
else RexxReqToolsLoaded = addlib('rexxreqtools.library',0,-30)
if (RexxReqToolsLoaded) then UserResponse = rtezrequest('Shall I download the new RECENT file now?',"_Yes|_No")
else do
say "[Warning: rexxreqtools.library not available!]"
say "Shall I download a new RECENT file now? (y/n)"
pull UserResponse
UserString = upper(UserResponse)
UserResponse = 1
if (left(UserString,1) == "N") then UserResponse = 0
end
if (UserResponse == 1) then DownloadRECENT = YES
else DownloadRECENT = NO
end
/* Fix up the syntax of some parameters */
if (right(AminetSite,1) ~= ":") then AminetSite = AminetSite || ":"
if (right(AminetRootDir,1) ~= "/") then AminetRootDir = AminetRootDir || "/"
/* Get a nice temporary filename or two */
ProcessID = time('S')
TempFile = "t:AutoFTP.temp." || ProcessID
BackupFile = "t:AutoFTP.script.bak"
TempRecent = "t:AutoFTP.RECENT." || ProcessID
GadMGetArgs = GadMGetArgs || " NOSIMPLEPATHS AMINETPATH " || AminetRootDir || " OUTPUT " || TempFile
LocalRecentFile = LocalRecentDir || "RECENT"
if (DownloadRECENT == YES) then do
/* Construct request for RECENT */
RECENTfile = AminetSite || AminetRootDir || "RECENT"
say "Retrieving the current RECENT file from " || AminetSite
GetRECENTCommand = ncFTP || " -r " || RECENTfile
/* Get RECENT file */
call Pragma('D',"t:")
success = DoCommand(GetRECENTCommand)
RenameCommand = "rename RECENT " || TempRecent || " QUIET"
success = DoCommand(RenameCommand)
call Pragma('D',LocalRECENTdir)
/* Now either process the downloaded RECENT file to save selected lines,
or if that's turned off, just copy it over. */
if (PreserveSelected = YES) then do
success = SmartCopy(LocalRecentFile,TempRecent,LocalRecentFile)
if (success == 0) then do
say "WARNING: File Merge failed. Falling back to simple copy"
CopyCommand = "copy " || TempRecent || " " || LocalRecentFile || " QUIET"
success = doCommand(CopyCommand)
end
end
else do
CopyCommand = "copy " || TempRecent || " " || LocalRecentFile || " QUIET"
success = doCommand(CopyCommand)
end
DeleteTempRecentCommand = "delete " || TempRecent || " QUIET"
success = DoCommand(DeleteTempRecentCommand)
end
/* Now we run GadMGet */
GadMGetCommand = GadMGet || " " || LocalRecentFile || " " || GadMGetArgs
success = DoCommand(GadMGetCommand)
/* Make sure that the output file is there */
if (~Exists(TempFile)) then do
say "You didn't select any files. Exiting..."
exit
end
/* Make a backup copy of GadMGet's output, that way if the ftp session
breaks, at least the user still has the last output to use manually
is s/he wants. */
BackupCommand = 'copy ' || TempFile || " " || BackupFile || " QUIET"
success = DoCommand(BackupCommand)
/* Let the user see the list... */
say "------FTP script is as follows-----"
address COMMAND "type " TempFile
say "-----------End FTP script----------"
/* Change to the directory the user wishes to download to */
call Pragma('D',DownloadDir)
DownloadCommand = ncFTP || " -r " || AminetSite || AminetRootDir || " <" || TempFile
success = DoCommand(DownloadCommand)
/* Now delete the Temporary file */
DeleteCommand = "delete " || TempFile || " QUIET"
success = DoCommand(DeleteCommand)
say "AutoFTP script terminating."
exit
/**************************************************************************/
/* ------------------------ BEGIN PROCEDURES ---------------------------- */
/**************************************************************************/
/* Executes an AmigaDos shell command for us, giving output if called for. */
DoCommand: procedure expose Debug
parse arg thiscommand
if (Debug == TRUE) then say "EXECUTING: [" || thiscommand || "]"
address COMMAND thiscommand
return 1
/* Looks at the current RECENT and the new one, and merges them so that:
1) All currently selected lines in the current RECENT are in the
output file's selected section
2) All currently selected lines in the current RECENT are NOT in
the output file's selectable section. */
SmartCopy: procedure expose Debug DoPruning
parse arg OldRecent, NewRecent, OutFile .
if (Debug == TRUE) then say "Merging " || OldRecent || " and " || NewRecent || " into " || Outfile
/* This needs to be accurate! */
BOOKMARK = "| --- GadMGet: Begin Selected Files --- "
/* Load OldRecent into OldRecentSel */
OSelIndex = 0
OKeepInput = 0
if ~open(OldInput, OldRecent, 'R') then return 0
do until eof(OldInput)
ThisLine = readln(OldInput)
if (ThisLine == BOOKMARK) then do
OKeepInput = 1
end
else do
if (OKeepInput == 1) then do
OldRecentSel.OSelIndex = ThisLine
OSelIndex = OSelIndex + 1
end
end
end
call close(OldInput)
if (OSelIndex == 0) then do
/* No selected lines to save. Might as well take the short cut */
CopyCommand = "copy " || NewRecent || " " || OutFile
success = DoCommand(CopyCommand)
return 1
end
/* Load NewRecent into NewRecent.Reg. Presumably since we just
downloaded this from Aminet, there won't be a NewRecent.Sel ! */
NewRecentRegIndex = 0
if ~open(NewInput, NewRecent, 'R') then return 0
if ~open(NewOutput,OutFile, 'W') then do
call close(NewInput)
return 0
end
do until eof(NewInput)
ThisLine = readln(NewInput)
CheckIndex = 0
OKToPrint = 1
if (DoPruning == YES) then do
do while ((CheckIndex < OSelIndex)&(OKToPrint = 1))
if (OldRecentSel.CheckIndex == ThisLine) then OKToPrint = 0
CheckIndex = CheckIndex + 1
end
end
if (OKToPrint == 1) then call writeln(NewOutput,ThisLine)
end
call close(NewInput)
/* Now write the bookmark, and our selected files */
call writeln(NewOutput,BOOKMARK)
WriteIndex = 0
do while (WriteIndex < OSelIndex)
call writeln(NewOutput,OldRecentSel.WriteIndex)
WriteIndex = WriteIndex + 1
end
call close(NewOutput)
return 1
/**************************************************************************/
/* ------------------------ END AUTOFTP SCRIPT CODE --------------------- */
/**************************************************************************/